
/**
 * 
 * 服务器访问地址
 */
var apiHost = "http://www.yeeyi.com/bbs/forum.php?jsoncallback=?&mod=mobile";

/**
 * 用于分页
 */
var noticePage = 1;
var b64 = new Base64();

function xmlHttp(url,callback){
	if(url == ''){
		uexWindow.alert('参数错误','请求地址不能为空！','返回');
	}else{
		var platform = getLocalStorge('platform');
		url = url + "&pf="+platform;
		$.getJSON(url,callback);
	}
}

function  getNoticeList(){
	//uexWindow.toast("1","5","数据加载中…","0");
	var uid = getLocalStorge('uid');
	if(!uid){
		//uexWindow.closeToast();
		alert('获取失败，请先登录！');
	}
	
	noticePage = 1;
	var url = apiHost + '&ac=notice&uid='+uid;
	xmlHttp(url,showList);
}

function showList(items){
	var returnCode = items[0].code;
	//uexWindow.closeToast();
	if(returnCode == '404'){
		//uexWindow.toast("0","5","加载失败，用户信息丢失，请先登录…","2000");
		alert("加载失败，用户信息丢失，请先登录!");
		return false;
	}
	
	var noticeObj = $("#forum_list");
	noticeObj.html('');
	var j = 0;
	for(var i in items){
		if(i > 0){
			j = j + 1;
			var item = items[j];
			var tr = '';
			var trHeader = '<div ontouchstart="zy_touch(\'btn-act\')" class="forumList" onclick="goThread('+item.relatedid+')"><div class="ub-f1 ub ub-ver">';
			var trOtherInfo = '<div class="otherInfo"><span>状态:'+b64.decode(item.isread)+'</span><span style="margin-left:1em;">时间:'+b64.decode(item.dateline)+'</span> <span style="margin-left:1em;"> 来源: '+b64.decode(item.author)+'</span></div>';
			var trDesc = '<div class="desc">'+b64.decode(item.note)+'</div>';
			var trFooter = '</div></div>';
			tr = trHeader+trOtherInfo+trDesc+trFooter;
			noticeObj.append(tr);
		}
	}
	//uexWindow.closeToast();
	
	if(j == 0){
		var tr = '';
		var trHeader = '<div ontouchstart="zy_touch(\'btn-act\')" class="forumList"><div class="ub-f1 ub ub-ver">';
		var trOtherInfo = '<div class="otherInfo"><span>提示:</span></div>';
		var trDesc = '<div class="desc">当前没有最新提示!</div>';
		var trFooter = '</div></div>';
		tr = trHeader+trOtherInfo+trDesc+trFooter;
		noticeObj.append(tr);
	}
	
	if(j == 10){
		$('.footer').removeClass('footerHide');
	}
}

function showMoreNotice(items){
	var noticeObj = $("#forum_list");
	var j = 0;
	for(var i in items){
		if(i > 0){
			j = j + 1;
			var item = items[j];
			var tr = '';
			var trHeader = '<div ontouchstart="zy_touch(\'btn-act\')" class="forumList" onclick="goThread('+item.relatedid+')"><div class="ub-f1 ub ub-ver">';
			var trOtherInfo = '<div class="otherInfo"><span>状态:'+b64.decode(item.isread)+'</span><span style="margin-left:1em;">时间:'+b64.decode(item.dateline)+'</span> <span style="margin-left:1em;"> 来源: '+b64.decode(item.author)+'</span></div>';
			var trDesc = '<div class="desc">'+b64.decode(item.note)+'</div>';
			var trFooter = '</div></div>';
			tr = trHeader+trOtherInfo+trDesc+trFooter;
			noticeObj.append(tr);
		}
	}
	uexWindow.closeToast();
	if(j == 10){
		$("#nextpage").text("查看下10条");
	}else{
		$("#nextpage").text("已经全部显示");
	}
	
}

function getMoreNotice(){
	var uid = getLocalStorge('uid');
	noticePage = noticePage + 1;
	var url = apiHost + '&ac=notice&uid='+uid+'&page='+noticePage;
	
	$("#nextpage").text("数据加载中……");
	xmlHttp(url,showMoreNotice);
}

function closeWindow(){
    var closeString = "uexWindow.close(-1);";
    uexWindow.evaluateScript('', '0', closeString);
}

function getLocalStorge(key){
	var item = localStorage.getItem(key);
	if(item=='' || item==null || typeof(item)=="undefined"){
		return false;
	}else{
		return item;
	}
}

/**
 * 帖子详情跳转函数
 * @param {Object} tid
 */
function goThread(tid){
	if(tid == '0'){
		return false;
	}else if(tid == ''){
		uexWindow.alert("ERROR","未指定帖子ID,无法加载帖子内容！","返回");
	}else{
		localStorage.setItem("tid",tid);
		var threadUrl = "viewthread.html";
		uexWindow.open("threadWindow",0,threadUrl,2,"","",0x0);
	}
}